package com.duowei.diandan.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.duowei.diandan.R;


public abstract class BaseToolbarActivity extends BaseActivity {

    private TextView mToolbarBackView;
    private TextView mToolbarTitleView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutRes());
        configureToolbar();
    }

    protected abstract int getLayoutRes();

    private void configureToolbar() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            // 隐藏返回箭头
            getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        }

        setTitle(null);
        mToolbarBackView = toolbar.findViewById(R.id.toolbar_back);
        mToolbarTitleView = toolbar.findViewById(R.id.toolbar_logo_txt);
        mToolbarBackView.setOnClickListener(v -> finish());
    }

    protected void setShowBackIcon(int visible) {
        mToolbarBackView.setVisibility(visible);
    }
}
